home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / vb / samples / misc / gpiomeas.frm < prev    next >
Encoding:
Text File  |  2001-03-02  |  2.2 KB  |  76 lines

  1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. '  This program does the following:
  3. '  - Creates a GPIO session with timeout and error checking
  4. '  - Signals the device with a CTL0 pulse
  5. '  - Reads the device's response using formatted I/O
  6. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  7. Sub cmdMeas_Click ()
  8.    Dim id As Integer                ' device session id
  9.    Dim retval As Integer            ' function return value
  10.    Dim buf As String                ' buffer for displaying
  11.    Dim real_data As Double          ' data from device
  12.  
  13. '  Set up an error handler within this subroutine that will
  14. '  be called if a SICL error occurs.
  15.    On Error GoTo ErrorHandler
  16.  
  17. '  Disable the button used to initiate I/O while I/O is
  18. '  being performed.
  19.    cmdMeas.Enabled = False
  20.  
  21. '  Open an interface session using a known symbolic name
  22.    id = iopen("gpio12")
  23.  
  24. '  Set the I/O timeout value for this session to 3 seconds
  25.    Call itimeout(id, 3000)
  26.  
  27. '  Setup formatted I/O configuration
  28.    Call igpiosetwidth(id, 8)
  29.    Call igpioctrl(id, I_GPIO_READ_EOI, 10)
  30.    
  31. '  Signal the device to take a measurement
  32.    Call itrigger(id)
  33.  
  34. '  Get the data
  35.    retval = ivscanf(id, "%lf%*t", real_data)
  36.  
  37. '  Display the response as string in a Message Box
  38.    buf = Str$(real_data)
  39.    retval = MsgBox(buf, MB_OK, "GPIO Data")
  40.  
  41. '  Close the device session.
  42.    Call iclose(id)
  43.  
  44. '  Enable the button used to initiate I/O
  45.    cmdMeas.Enabled = True
  46.    
  47.    Exit Sub
  48.  
  49. ErrorHandler:
  50.  
  51. '  Display the error message string in a Message Box
  52.    retval = MsgBox(Error$, MB_ICONEXCLAMATION, "SICL Error")
  53.  
  54. '  Close the device session if iopen was successful.
  55.    If id <> 0 Then
  56.       iclose (id)
  57.    End If
  58.    
  59. '  Enable the button used to initiate I/O
  60.    cmdMeas.Enabled = True
  61.  
  62.    Exit Sub
  63.  
  64. End Sub
  65.  
  66. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  67. '  The following routine is called when the application's
  68. '  Start Up form is unloaded.  It calls siclcleanup to
  69. '  release resources allocated by SICL for this
  70. '  application.
  71. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  72. Sub Form_Unload (Cancel As Integer)
  73.    Call siclcleanup    ' Tell SICL to clean up for this task
  74. End Sub
  75.  
  76.